﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FacebookWrapper.ObjectModel;

namespace B12_Ex03_Eran_053094363_Assaf_036722999
{
    public partial class FriendDetails : Form
    {
        private User m_DetailedUser;

        public FriendDetails()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Shows the Friend Details Dialog with all the Friends Details
        /// </summary>
        /// <param name="i_FriendUser">The Facebook user of the Friend to show</param>
        public void ShowDetails(User i_FriendUser)
        {
            m_DetailedUser = i_FriendUser;
            setFormText(m_DetailedUser.Name);
            fillFormDetails();
            ShowDialog();
        }

        private void fillFormDetails()
        {
            try
            {
                // Get the User Picture
                picProfilePicture.LoadAsync(m_DetailedUser.PictureLargeURL);
                
                // Fill in the User Basic Details
                txtFirstName.Text = m_DetailedUser.FirstName;
                txtLastName.Text = m_DetailedUser.LastName;
                
                // Check if the User has a Middle Name to Show
                if (!string.IsNullOrEmpty(m_DetailedUser.MiddleName))
                {
                    txtMiddleName.Text = m_DetailedUser.MiddleName;
                    txtMiddleName.Visible = true;
                }
                else
                {
                    txtFirstName.Size = new Size(229, 20);
                }

                // Set the Gender text and Image
                txtGender.Text = m_DetailedUser.Gender.ToString();
                
                // Check the Intrested in Field - if Exists put the Relevant Picture
                if (m_DetailedUser.InterestedIn != null && m_DetailedUser.InterestedIn.Length > 0)
                {
                    if (m_DetailedUser.Gender == User.eGender.male)
                    {
                        if (m_DetailedUser.InterestedIn[0] == User.eGender.male)
                        {
                            picGenderSymbol.Image = Properties.Resources.Male_symbol_color;
                        }
                        else if (m_DetailedUser.InterestedIn[0] == User.eGender.female)
                        {
                            picGenderSymbol.Image = Properties.Resources.Male_symbol_normal;
                        }
                    }
                    else if (m_DetailedUser.Gender == User.eGender.female)
                    {
                        if (m_DetailedUser.InterestedIn[0] == User.eGender.female)
                        {
                            picGenderSymbol.Image = Properties.Resources.Female_symbol_color;
                        }
                        else if (m_DetailedUser.InterestedIn[0] == User.eGender.male)
                        {
                            picGenderSymbol.Image = Properties.Resources.Female_symbol_normal;
                        }
                    }
                    else
                    {
                        picGenderSymbol.Image = picGenderSymbol.ErrorImage;
                    }
                }
                else
                {
                    picGenderSymbol.Visible = false;
                }
                
                // Get all the Email Addresses of the User
                if (m_DetailedUser.Email != null)
                {
                    if (m_DetailedUser.Email.Length > 1)
                    {
                        txtEmail.Multiline = true;
                        foreach (var email in m_DetailedUser.Email)
                        {
                            txtEmail.Text += email;
                            txtEmail.Size = new Size(txtEmail.Width, txtEmail.Height + 20);
                        }
                    }
                }

                txtBirthDay.Text = m_DetailedUser.Birthday;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void setFormText(string i_FormText)
        {
            this.Text = i_FormText;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnPostMessage_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtMessageToPost.Text) && !string.IsNullOrWhiteSpace(txtMessageToPost.Text))
            {
                m_DetailedUser.PostStatus(txtMessageToPost.Text);
            }
            else
            {
                MessageBox.Show("Will not Post an Empty Status Message...");
            }
        }
    }
}
